home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0921.ZIP / JOYSTK.ARC / JOYDEMO3.PAS < prev    next >
Pascal/Delphi Source File  |  1987-03-29  |  4KB  |  162 lines

  1. program JoyDemo3;
  2.  
  3. {
  4. Author:        David Howorth
  5. Last updated:  March 29, 1987
  6. Application:   A demonstration of procedure ReadJoy, a procedure for
  7.                reading the joystick, using variable parameters.  Shows
  8.                how to use the joystick as a POSITION indicator.
  9. }
  10. {$C-}
  11. { Above compiler directive necessary so that 'keypressed' function works
  12.   properly.  Also speeds up screen output.                               }
  13.  
  14. var
  15.   ch         :   char;
  16.   JoyX,
  17.   JoyY,
  18.   Dummy      :   integer;
  19.   XDivisor,
  20.   YDivisor   :   integer;
  21.  
  22. {$I READJOY.INC}
  23. {$I BUTTONS.INC}
  24.  
  25. {--------------------------------------}
  26.  
  27. procedure FatCursor(Fat : boolean);
  28.  
  29. var
  30.   Reg    : record
  31.              ax,bx,cx,dx,bp,si,di,ds,es,flags : integer;
  32.            end;
  33.  
  34. {----------------}
  35.  
  36. function MonochromeScreen : boolean;
  37.  
  38. begin
  39.   MonochromeScreen := (mem[0:$449] = 7);
  40. end; { function MonochromeScreen }
  41.  
  42. {----------------}
  43.  
  44. begin { procedure FatCursor }
  45.   if Fat
  46.     then if MonochromeScreen
  47.            then Reg.cx := $000D
  48.            else Reg.cx := $0007
  49.     else if MonochromeScreen
  50.            then Reg.cx := $0C0D
  51.            else Reg.cx := $0607;
  52.   Reg.ax := $0100;
  53.   intr($10,Reg);
  54. end; { procedure FatCursor }
  55.  
  56. {--------------------------------------}
  57.  
  58. procedure Initialize;
  59.  
  60. var
  61.   LowX,
  62.   LowY,
  63.   HighX,
  64.   HighY   :   integer;
  65.  
  66. {----------------}
  67.  
  68. procedure CalibrateJoystick;
  69.  
  70. begin
  71.   writeln('                         JOYSTICK DEMONSTRATION NUMBER 3');
  72.   writeln;
  73.   writeln('                        (Joystick as position indicator)');
  74.   gotoxy(1,7);
  75.   writeln('You may want to try this demo with the joystick unlocked.');
  76.   gotoxy(1,9);
  77.   writeln('Move joystick to upper-left corner and press one of its buttons.');
  78.   repeat until ButtonA1 or ButtonA2;
  79.   ReadJoy(LowX,LowY,Dummy,Dummy);
  80.   writeln('Move joystick to lower-right corner and press one of its buttons.');
  81.   delay(300);
  82.  
  83. { Note this delay.  You have to give the joystick button a chance to settle
  84.   down before you test it again.                                             }
  85.  
  86.   repeat until ButtonA1 or ButtonA2;
  87.   ReadJoy(HighX,HighY,Dummy,Dummy);
  88.   XDivisor := (HighX div 80) + 1;
  89.   YDivisor := (HighY div 25) + 1;
  90.   gotoxy(1,15);
  91.   writeln('Once the demonstration begins, you may end it by');
  92.   writeln('pressing one of the joystick buttons.');
  93.   delay(2000);
  94.   writeln;
  95.   writeln('Now press one of the buttons to begin.');
  96.   repeat until ButtonA1 or ButtonA2;
  97. end; { procedure CalibrateJoystick }
  98.  
  99. {----------------}
  100.  
  101. procedure Box(x1,y1,x2,y2 : integer);
  102.  
  103. var
  104.   i : integer;
  105.  
  106. begin
  107.   gotoXY(x1,y1);
  108.   write(char(218));
  109.   for i := x1 + 1 to x2 - 1 do write(char(196));
  110.   write(char(191));
  111.   for i := y1 + 1 to y2 - 1 do
  112.   begin
  113.     gotoXY(x1,i);
  114.     write(char(179));
  115.     gotoXY(x2,i);
  116.     write(char(179));
  117.   end;
  118.   gotoXY(x1,y2);
  119.   write(char(192));
  120.   for i := x1 + 1 to x2 - 1 do write(char(196));
  121.   write(char(217));
  122. end; { procedure Box }
  123.  
  124. {----------------}
  125.  
  126. begin { procedure Initialize }
  127.   clrscr;
  128.   CalibrateJoystick;
  129.   clrscr;
  130.   LowX := (LowX div XDivisor) - 1;
  131.   if LowX < 1 then LowX := 1;
  132.   HighX := (HighX div XDivisor) + 1;
  133.   if HighX > 80 then HighX := 80;
  134.   LowY := (LowY div YDivisor) - 1;
  135.   if LowY < 1 then LowY := 1;
  136.   HighY := (HighY div YDivisor) + 1;
  137.   if HighY > 25 then HighY := 25;
  138.   Box(LowX,LowY,HighX,HighY);
  139.   FatCursor(true);
  140.   while keypressed do read(kbd,ch);   { empty keyboard buffer }
  141. end; { procedure Initialize }
  142.  
  143. {--------------------------------------}
  144.  
  145. procedure Abort;
  146.  
  147. begin
  148.   FatCursor(false);
  149.   clrscr;
  150. end;
  151.  
  152. {--------------------------------------}
  153.  
  154. begin { main program }
  155.   Initialize;
  156.   repeat
  157.     ReadJoy(JoyX,JoyY,Dummy,Dummy);
  158.     gotoxy((JoyX div XDivisor),(JoyY div YDivisor));
  159.   until ButtonA1 or ButtonA2 or keypressed;
  160.   Abort;
  161. end.
  162.